﻿#!/usr/bin/env python
"""
-->
FileInfo = "Defines which files you like to work with."
FilePath = {'type': "System.String", 'description': "Path of the file you like to work with.", 'validation': "IsFile"}
-->

<--
FileData = "Defines the data, which was read from the given files."
FilePath = {'type': "System.String", 'description': "Path of the file you like to work with.", 'validation': "IsFile"}
Content = {'type': "System.String", 'description': "The file content."}
<--
"""

from MyClever.Lib import MissionPlugin

__author__ = "Mathias Mielitz"
__copyright__ = "Copyright 2012, MyCleverFriend"
__credits__ = ["Mathias Mielitz"]
__license__ = "GPL"
__version__ = "1.0.0.0"
__maintainer__ = "Mathias Mielitz"
__email__ = "m.mielitz@adrabbit.de"
__status__ = "Production"
__description__ = "Reads the content from every given file."

class ReadFile(MissionPlugin):
	def Work(self):

		fileInfoPackage = self.GetDataReader("FileInfo")
		while fileInfoPackage.Read():
			self.AddNewLoggingMessage("FileInfo", "read file: " + fileInfoPackage["FilePath"]);

			fileContent = open(fileInfoPackage["FilePath"], "r").read();

			newRow = self.CreateNewRowFromPackage("FileData");
			newRow["FilePath"] = fileInfoPackage["FilePath"].ToString();
			newRow["Content"] = fileContent;
			self.AddNewRowToPackage("FileData", newRow);